/*
 * @Description: 
 * @Author: BaldHead
 * @Date: 2022-04-12 17:24:28
 * @LastEditTime: 2022-04-12 17:25:54
 * @LastEditors: Please set LastEditors
 */

var parse = function(obj, str) {
    let ans = undefined;
    let arr = []
    for (let index = 0; index < str.length; index++) {
        const element = str[index];
        if (element == '.' || element == "[" || element == "]") {
            continue;
        } else {
            arr.push(element)
        }
    }
    ans = object;
    for (let index = 0; index < arr.length; index++) {
        const element = arr[index];
        // console.log(element);
        if (ans[element]) {
            ans = ans[element];
        } else {
            ans = 'undefined';
        }

    }
    return ans;
}
var object = {
    b: { c: 4 },
    d: [{ e: 5 }, { e: 6 }]
};
console.log(parse(object, 'b.c') == 4) //true
console.log(parse(object, 'd[0].e') == 5) //true
console.log(parse(object, 'd.0.e') == 5) //true
console.log(parse(object, 'd[1].e') == 6) //true
console.log(parse(object, 'd.1.e') == 6) //true
console.log(parse(object, 'f') == 'undefined') //true